
function testMethod2() {
    var person = {name:'lll',age:18}
    person.greetfn = function () {
        var that = this
        return function () {
            console.log(`hello, ${that.name}`)
        }
    }
    person.greetfn()()
}

function testResultCallbackFunc(resolve,reject) {
    var timeout = Math.random() * 2
    console.log('set timeout to: '+timeout+' seconds')
    setTimeout(function () {
        if (timeout < 1) {
            console.log('call resolve()...')
            resolve('200 ok')
        }
        else {
            console.log('call reject()...')
            reject('timeout in '+ timeout+' seconds')
        }
    },timeout * 1000)
}


function testResultCallback() {
    success = (message) => {console.log(`success ${message}`)}
    failed = (error) => {console.log(`failed ${error}`)}
    testResultCallbackFunc(succes,failed)
    Promise
}

function testWithPromise() {
    var p1 = new Promise(testResultCallbackFunc)
    p1.then((resp) => {
        console.log(resp)
    }).catch((err) => {
        console.log(err)
    })
}

async function testWithAsync() {
    var p1 = new Promise(testResultCallbackFunc)
    try {
        var resp = await p1
        console.log(resp)
    } catch (err) {
        console.log(err)
    }
}


function main() {
    function callback() {
        console.log('Done')
    }
    console.log('before settimeout()')
    setTimeout(callback,1000)
}

testWithAsync()



